package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> list(Long userId);

    /**
     * 根据用户id删除购物车数据
     *
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void cleanShoppingCart(Long userId);

    /**
     * 根据 dishId 和 setmealId 查询购物车
     *
     * @param userId
     * @param dishId
     * @param setmealId
     */
    ShoppingCart getShoppingCartByDishIdAndSetmealId(Long userId, Long dishId, Long setmealId);

    /**
     * 根据 Id 修改购物车数据
     *
     * @param id
     * @param newNumber
     * @param newAmount
     */
    @Update("update shopping_cart set number = #{newNumber}, amount = #{newAmount} where id = #{id}")
    void updateShoppingCart(Long id, Integer newNumber, BigDecimal newAmount);

    @Insert("insert into shopping_cart (name,image,user_id,dish_id,setmeal_id,dish_flavor,number,amount,create_time) values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void save(ShoppingCart shoppingCart);
}
